package com.learning.code.multithread.keyword.singleton;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/***
 *  枚举实现 单例
 */
public class MyObject {

    public enum MyEnumSingleton{

        INSTANCE;
        private Connection connection;

        private MyEnumSingleton(){

            try {
                //todo
                String url ="jdbc:sqlserver://localhost:1079;databaseName=y2";
                connection = DriverManager.getConnection(url,"222","2333");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        public Connection getConnection(){
            return connection;
        }
    }

    public static Connection getConnection(){
        return MyEnumSingleton.INSTANCE.getConnection();
    }
}
